#ifndef _AMERICO_OCT_TREE_MAP_H_
#define _AMERICO_OCT_TREE_MAP_H_

#include <Intersection/Box.h>
#include "OctTreeCell.h"

template <typename T>
class OctTreeMap
{
public:
	OctTreeMap();
	~OctTreeMap();

	void Init(const Vector3<float> &aCenter, const Vector3<float> &someExtents, const unsigned int &aNumberOfObjects=3, const unsigned int &aMaxDepth=4);

	inline void SetDynamic(const bool &aDynamicFlag=true) { myRoot->SetDynamic(aDynamicFlag); }
	inline void SetMaxObjects(const unsigned int &aNumberOfObjects) { myRoot->SetMaxObjects(aNumberOfObjects); }
	inline void SetMaxDepth(const unsigned int &aMaxDepth) { myRoot->SetMaxDepth(aMaxDepth); }

	void InsertObject(T *aDweller);

	inline OctTreeCell<T> *GetRoot() const { return myRoot; }

	inline bool IsDynamic() const { return myRoot->IsDynamic(); }
	inline unsigned int MaxObjects() const { return myRoot->MaxObjects(); }
	inline unsigned int MaxDepth() const { return myRoot->MaxDepth(); }

private:
	OctTreeCell<T> *myRoot;
};

template <typename T>
OctTreeMap<T>::OctTreeMap()
{
	myRoot = new OctTreeCell<T>();
	myRoot->SetRoot(myRoot);
}

template <typename T>
OctTreeMap<T>::~OctTreeMap()
{
	if(myRoot != 0)
	{
		delete myRoot;
		myRoot = 0;
	}
}

template <typename T>
void OctTreeMap<T>::Init(const Vector3<float> &aCenter, const Vector3<float> &someExtents, const unsigned int &aNumberOfObjects, const unsigned int &aMaxDepth)
{
	myRoot->Init(aCenter, someExtents, aNumberOfObjects, aMaxDepth);
}

template <typename T>
void OctTreeMap<T>::InsertObject(T *aDweller)
{
	myRoot->AddObject(aDweller);
}

#endif